<?php

namespace App\Http\Controllers;

use App\Services\Service\ServiceFactory;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $_CallbackService;
    protected $_resource;

    /**
     * 异步错误信息输出
     * @param string $message
     * @param null $_data
     * @return array
     */
    protected function _error(string $message,$_data = null){
        return ['error_message' => $message , 'data' => $_data ?? [] , 'success' => false];
    }

    /**
     *
     * 异步成功信息输出
     *
     * @param string $message
     * @param null $_data
     * @return array
     */
    protected function _msg(string $message,$_data = null){
        return ['msg_message' => $message , 'data' => $_data ?? [] , 'success' => true];
    }

    /**
     *
     * 注册服务
     *
     * @return mixed
     */
    protected function _CallbackService()
    {
        if (!$this->_CallbackService){
            return (new ServiceFactory())->createService($this->_resource);
        }
        return $this->_CallbackService;
    }

}
